#include "searcher.hpp"
#include "httplib/httplib.h"
const std::string root_path = "./wwwroot";
const std::string input = "data/raw_html/raw.txt";

int main()
{
    Searcher::searcher sch;
    sch.InitSearcher(input);

    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());
    svr.Get("/s", [&sch](const httplib::Request& req, httplib::Response& resp){
        if(!req.has_param("word"))
        {
            resp.set_content("必须得有搜索关键字!", "text/plain; charset=utf-8");
            return 1;
        }
        const std::string word = req.get_param_value("word");
        std::cout << "用户在搜索：" << word << std::endl;
        std::string json_string;
        sch.search(word, &json_string);
        resp.set_content(json_string, "application/json");
    });
    svr.listen("0.0.0.0", 8081);

    return 0;
}

